﻿# Author: Padisetty
# Copyright 2013, Licensed under Apache License 2.0
#

function GetIpConfig()
{
    md c:\temp -ea 0
    ipconfig > c:\temp\ipconfig.txt
}

function RemoveIpConfig()
{
    del c:\temp\ipconfig.txt -ea 0
}


function IISSetup ($Ensure = "Present")
{
    configuration WebConfig
    {
        WindowsFeature IIS
        {
            Name="Web-Server"
            Ensure=$Ensure
        }
    }
    WebConfig -OutputPath C:\temp\config  -ConfigurationData $AllNodes
    Start-DscConfiguration c:\temp\config -ComputerName localhost -Wait -verbose -force
}

function ChefInstall ([string]$MSIPath)
{

    $recipe = @"
file 'c:/temp/helloworld.txt' do
  content 'hello world'
end

remote_file 'c:/temp/7zip.msi' do
  source "http://www.7-zip.org/a/7z938-x64.msi"
end

windows_package '7-Zip 9.38 (x64 edition)' do
  source 'c:/temp/7zip.msi'
  action :install
end
"@
    configuration ChefConfig
    {
        File SevenZip
        {
            DestinationPath = 'c:\temp\7zip.rb'
            Contents = $Recipe
        }
        Package ChefPackage
        {
            Path = $MSIPath
            Name = "Chef Client v12.0.3"
            Ensure = "Present"
            ProductId = ""
        }
    }

    ChefConfig -OutputPath C:\temp\config  -ConfigurationData $AllNodes
    Start-DscConfiguration c:\temp\config -ComputerName localhost -Wait -verbose -force

    C:\opscode\chef\bin\chef-apply.bat C:\temp\7zip.rb | Out-File 'c:\temp\chef-apply.log'
}

#ChefInstall -MSIPath 'http://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.0.3-1.msi'
